Back to course home
0% completed
Vote For New Content
Microsoft Hard Problems
Regular Expression Matching (hard)
Solution: Regular Expression Matching
First Missing Positive (hard)
Solution: First Missing Positive
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Sliding Window Maximum (hard)
Solution: Sliding Window Maximum
Count Unique Characters of All Substrings of a Given String (hard)
Solution: Count Unique Characters of All Substrings of a Given String
Word Ladder (hard)
Solution: Word Ladder
Word Ladder II (hard)
Solution: Word Ladder II
Number of Flowers in Full Bloom (hard)
Solution: Number of Flowers in Full Bloom
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Remove Duplicate Letters (medium)
Problem Statement
Given a string s, remove all duplicate letters from the input string while maintaining the original order of the letters.
Additionally, the returned string should be the smallest in lexicographical order among all possible results.
A string is in the smallest lexicographical order if it appears first in a dictionary. For example, "abc" is smaller than "acb" because "abc" comes first alphabetically.
Examples:
-
- Input: "babac"
- Expected Output: "abc"
- Justification:
- After removing 1
band 1afrom the input string, we can getbac, andabcstrings. The final answer is 'abc', which is the smallest lexicographical string without duplicate letters.
- After removing 1
-
- Input: "zabccde"
- Expected Output: "zabcde"
- Justification: Removing one of the 'c's forms 'zabcde', the smallest string in lexicographical order without duplicates.
-
- Input: "mnopmn"
- Expected Output: "mnop"
- Justification: Removing the second 'm' and 'n' gives 'mnop', which is the smallest possible string without duplicate characters.
Constraints:
- 1 <= s.length <= 104
- s consists of lowercase English letters.
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Largest Palindromic Number
Solution: Remove Duplicate Letters
Mark as Completed
On this page
Problem Statement
Try it yourself